package ke07.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UDPServer {
	public static void main(String[] args) {

		byte[] receiveData = new byte[1024];
		
		DatagramSocket serverSocket = null;
		try {
			serverSocket = new DatagramSocket(9876);
		} catch (SocketException e1) {
			e1.printStackTrace();
		}
		while (true) {
			try {
				// Variable fuer eingehende UDP Pakete
				DatagramPacket receivePacket = new DatagramPacket(receiveData,
						receiveData.length);
				System.out.println("Warte auf Paket...");
				// Warten auf eingehende UDP Pakete; weiter, wenn Paket eingetroffen
				serverSocket.receive(receivePacket);
				System.out.println("Verarbeite ein Paket...");
				new UDPServerThread(serverSocket, receivePacket).start();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
